from django.db import models


class TypeInfo(models.Model):
    ttitle = models.CharField(max_length=20)
    isDelete = models.BooleanField(default=False)
    # 如果不加这个，外键将会在admin页面显示TypeInfo object
    def __str__(self):
        return self.ttitle


class GoodsInfo(models.Model):
    gtitle = models.CharField(max_length=20)
    gpic = models.ImageField(upload_to='df_goods')
    gprice = models.DecimalField(max_digits=5, decimal_places=2)
    isDelete = models.BooleanField(default=False)
    gunit = models.CharField(max_length=20, default='500g')
    gclick = models.IntegerField()
    gjianjie = models.CharField(max_length=200)
    gkucun = models.IntegerField()
    # gcontext = HTMLField()
    gcontext = models.TextField()
    gtype = models.ForeignKey(TypeInfo, null=True, blank=True, on_delete=models.SET_NULL)
    # gadv = models.BooleanField(default=False)

    def __str__(self):
        return self.gtitle

